﻿package mortal.game.view.medal
{
    import Message.DB.Tables.*;
    import flash.events.*;
    import mortal.component.window.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class MedalController extends Controller
    {
        private var _module:MedalModule;

        public function MedalController()
        {
            return;
        }// end function

        override protected function initView() : IView
        {
            if (this._module == null)
            {
                this._module = new MedalModule();
                this._module.addEventListener(WindowEvent.SHOW, this.onWinShow);
                this._module.addEventListener(WindowEvent.CLOSE, this.onWinClose);
            }
            return this._module;
        }// end function

        override protected function initServer() : void
        {
            NetDispatcher.addCmdListener(ServerCommand.MedalAdd, this.medalAdd);
            Dispatcher.addEventListener(EventName.MedalOpen, this.openWin);
            return;
        }// end function

        private function onWinShow(event:Event) : void
        {
            return;
        }// end function

        private function onWinClose(event:Event) : void
        {
            return;
        }// end function

        private function openWin(event:DataEvent) : void
        {
            if (view.isHide)
            {
                view.show();
            }
            else
            {
                view.hide();
            }
            return;
        }// end function

        private function medalAdd(param1:TMedal) : void
        {
            if (this.isViewShow)
            {
                this._module.updateMedal();
            }
            return;
        }// end function

    }
}
